/**
* @file 首页
* @author 张超
* @created 2023/6/29 17:00
* @updated 2023/6/29 18:00
*/

<template>
	<view class="index" :style="{ background: 'url(' + bfd + ')', backgroundSize: '100% 100% !important' }">
		<!-- 头部 -->
		<view class="head" :style="{ background: 'url(' + rankingBgData + ')', backgroundSize: '100% 100% !important' }">
			<view class="head-seach">
				<u-icon name="search" color="#707070" size="35"></u-icon>
				<input type="text" v-model="keyword" @confirm="blur" placeholder="请输入关键字">
				<u-icon @click="saom" name="scan" color="#707070" size="35"></u-icon>
			</view>
		</view>
		<!-- 古传十三方 -->
		<view class="gc">
			<u-swiper :list="swlist" height="360" border-radius="15"></u-swiper>
		</view>
		<!-- 通知 -->
		<view class="inform">
			<!-- <u-notice-bar mode="horizontal" :list="list" bg-color="#fff"></u-notice-bar> -->
			<uni-notice-bar speed="10" show-icon scrollable :text="list" />
		</view>
		<!-- 金刚区 -->
		<ul class="jg">
			<li v-for="(item1, index1) in leftList" :key="index1" @click="goKind(item1.id)">
				<image :src="item1.image_text"></image>
				<text>{{ item1.name }}</text>
			</li>
		</ul>
		<!-- 健康值 -->
		<view class="jiank">
			<view class="">
				<text>全网总健康值</text>
				<text>{{ jiankde.all }}</text>
			</view>
			<view class="">
				<text>个人健康值</text>
				<text>{{ jiankde.own }}</text>
			</view>
		</view>
		<!-- 秒杀 -->
		<view class="seckill">
			<view class="seckill-left">
				<view @click="goSeckill">
					<image src="@/static/index/miaos-img.png"></image>
					<text>查看全部></text>
				</view>
				<ul>
					<li v-for="(item2, index2) in miaosde" :key="index2" @click="goSeckillDetail(item2.id)">
						<image :src="item2.goodsimage_text"></image>
						<text>{{ item2.goodsname }}</text>
						<view :style="{ background: 'url(' + fsa + ')', backgroundSize: '100% 100% !important' }">
							<text>抢</text>
							<view>{{ item2.sgoodssalenum | xiaos }}<text style="">积分</text></view>
						</view>
					</li>
				</ul>
			</view>
			<view class="seckill-right">
				<view @click="goSign" :style="{ background: 'url(' + fdw1 + ')', backgroundSize: '100% 100% !important' }">
					<text>签到领积分</text>
					<text>去签到</text>
				</view>
				<view v-if="configDe.applyStatus == 0" @click="gojifc"
					:style="{ background: 'url(' + fdw2 + ')', backgroundSize: '100% 100% !important' }">
					<text>充值中心</text>
					<text class="active">去充值</text>
				</view>
			</view>
		</view>
		<!-- 热销榜单 -->
		<view class="hot">
			<view class="hot-logo">
				<text>HUO</text>
				<text>热</text>
				<text>DONG</text>
			</view>
			<view class="hot-title">热销榜单</view>
			<view class="hot-titlesd">好物榜单 健康热销</view>
			<image v-if="configDe.hotImage" class="title-img" :src="configDe.hotImage" mode=""></image>
			<ul>
				<li v-for="(item3, index3) in hotList" :key="index3" @click="detail(item3.id)">
					<image :src="item3.goodsimage_text"></image>
					<text>{{ item3.goodsname }}</text>
					<view>{{ item3.goodsprice | xiaos }}<text class="hot-icon">金币</text>+{{ item3.goodssalenum | xiaos }}<text
							class="hot-icon">积分</text></view>
					<text>{{ item3.desc }}</text>
				</li>
			</ul>
		</view>
		<!-- 最新活动 -->
		<view class="hot">
			<view class="hot-logo">
				<text>HUO</text>
				<text>热</text>
				<text>DONG</text>
			</view>
			<view class="hot-title">最新活动</view>
			<view class="hot-titlesd">好物榜单 健康热销</view>
			<image v-if="configDe.newImage" class="title-img" :src="configDe.newImage" mode=""></image>
			<ul>
				<li v-for="(item4, index4) in loadmoreList" :key="index4" @click="detail(item4.id)">
					<image :src="item4.goodsimage_text"></image>
					<text>{{ item4.goodsname }}</text>
					<view>{{ item4.goodsprice | xiaos }}<text class="hot-icon">金币</text>+{{ item4.goodssalenum | xiaos }}<text
							class="hot-icon">积分</text></view>
					<text>{{ item4.desc }}</text>
				</li>
			</ul>
		</view>
		<view style="height:100rpx;"></view>
		<!-- 弹框 -->
		<u-popup v-model="show" mode="center" width="630" border-radius="10">
			<view class="pop">
				<!-- <view class="pop-title">
					<text></text>
					<text>公告</text>
					<text></text>
				</view>
				<view class="pop-cont">
					尊敬的用户因支付系统升级，近期进行银行资金通道改造，部分使用银行卡的管家计划将受到影响，敬请关注您近期计划的执行情况。恢复时间另行通知，对您使用造成的不便深表歉意。尊敬的用户因支付系统升级，近期进行银行资金通道改造，部分使用银行卡的管家计划将受到影响，敬请关注您近期计划的执行情况。恢复时间另行通知，对您使用造成的不便深表歉意。
				</view>
				<view class="pop-btn" @click="confirm">我知道了</view> -->
				<image style="width:100%;height:700rpx;" :src="configDe.indexOutImage"></image>
			</view>
		</u-popup>
		<u-modal v-model="sbshow" title="获取扫码权限" @confirm="confirmdad" :content="content"
			show-cancel-button="false"></u-modal>
	</view>
</template>

<script>
import {
	getUserInfo,
	goods_list,
	config,
	kind,
	doRotation,
	binding,
	healthInfo
} from '@/network/api.js'
export default {
	data() {
		return {
			sbshow: false,
			bfd: '/static/index/bfd.png',
			fsa: '/static/index/fsa.png',
			fdw2: '/static/index/integral.png',
			fdw1: '/static/index/sign.png',
			rankingBgData: '/static/index/index-bg.png',
			content: 'App需要您的同意才能访问相机或存储空间，用于拍照、扫码、存储图片场景下的使用',
			list: '',
			// 热销榜列表数据
			hotList: [],
			// 活动列表数据
			page: 1,
			loadmoreList: [],
			// 是否显示弹框
			show: false,
			// 配置数据
			configDe: {},
			// 搜索关键字
			keyword: "",
			// 分类数据
			leftList: [],
			// 描述
			miaosDa: [],
			// 轮播图
			swlist: [],
			// 秒杀数据
			miaosde: [],
			// 健康值
			jiankde: {}
		}
	},
	onLoad() {
		this.in()
		this.kinRe()
		this.loadmoreRe()
		this.miaos()
		this.jiankRe()
	},
	onShow() {
		uni.removeStorageSync('kind_id')
		this.miaos()
		this.configRe()
		this.jiankRe()
	},
	onReachBottom() {
		this.page++
		this.miaos()
		this.loadmoreRe()
	},
	filters: {
		// 过滤小数点后面数据
		xiaos(num) {
			return Math.trunc(num)
		},
	},
	methods: {
		confirmdad() {
			this.opens()
		},
		saom() {
			this.sbshow = true
		},
		// 扫一扫
		opens() {
			let that = this
			uni.scanCode({
				success: function (res) {
					console.log('条码类型：' + res.scanType);
					console.log('条码内容：' + res.result);
					let str = res.result
					let type = str.slice(0, 5) //类型
					// group参团/score互转
					if (type == 'group') {
						// 截取id
						let idw = ''
						let team_snsw = ''
						var index1 = str.indexOf("-");
						var index2 = str.indexOf("-", index1 + 1);
						var index3 = str.indexOf("-", index2 + 1);
						idw = str.substring(index2 + 1, index3);

						// 截取编号
						var index = str.indexOf("-", str.indexOf("-", str.indexOf("-") + 1) + 1) + 1;
						team_snsw = str.substring(index);
						let obj = {
							id: idw,
							team_sn: team_snsw
						}
						let data = {
							type: 2,
							number: 1,
							typee: 1,
							market: obj
						}
						uni.navigateTo({
							url: '/pages/subpackage/shop/qconfig?data=' + JSON.stringify(data)
						})
					} else if (type == 'score') {
						let ied = str.slice(11)
						let data = {
							id: ied
						}
						that.doRotationRe(data)
					} else {
						let uid = ''
						const index4 = str.indexOf("-");
						uid = str.slice(index4 + 1);
						let data = {
							id: uid
						}
						that.bangd(data)
					}
				}
			});
		},
		cih(item) {
			console.log(item, '词汇')
			uni.navigateTo({
				url: '/pages/subpackage/shop/search?data=' + item
			})
		},
		// 扫码领取奖励
		doRotationRe(ied) {
			console.log(ied, '领取奖励')
			doRotation(ied).then(res => {
				if (res.code == 1) {
					uni.showToast({
						title: '领取成功',
						duration: 2000,
						icon: 'none'
					});
				}
			})
		},
		// 绑定上下级
		bangd(uid) {
			console.log(uid, '绑定上下级')
			uni.navigateTo({
				url: '/pages/subpackage/shop/web?url=' + uid.id
			})
			// binding(uid).then(res=>{
			// 	if(res.code==1){
			// 		uni.showToast({
			// 			title: '绑定成功',
			// 			duration: 2000,
			// 			icon: 'none'
			// 		});
			// 	}
			// })
		},
		// 获取左侧分类
		kinRe() {
			let data = {
				type: 'default',
				limit: 0
			}
			kind(data).then(res => {
				this.leftList = res.data
				// if (this.leftList.length > 0) {
				// 	this.loadmoreRe(this.leftList[0].id)
				// }
			})
		},
		// 获取热销榜数据
		in() {
			let data = {
				is_killing: 0,
				object: 'hot',
				limit: 1
			}
			goods_list(data).then(res => {
				this.hotList = res.data
			})
		},
		// // 获取热销榜数据
		jiankRe() {
			healthInfo().then(res => {
				this.jiankde = res.data
				console.log(res, '首页健康值')
			})
		},
		// 获取秒杀
		miaos() {
			let data = {
				is_killing: 1,
				// object: 'hot',
				limit: 2
			}
			goods_list(data).then(res => {
				this.miaosde = res.data
				console.log(this.miaosde, '秒杀')
			})
		},
		// 配置接口
		configRe() {
			config().then(res => {
				this.list=res.data.indexNotice
				this.configDe = res.data
				if (this.configDe.indexOutImage != '') {
					// if (uni.getStorageSync("indexp")!='') {
						this.show = true
					// }else{
						// this.show = true
						// uni.setStorage({ key: "indexp", data: 'open' });
					// }
				}
				let data = JSON.parse(res.data.hotSearch)
				let data2 = []
				for (let key in data) {
					data2.push(data[key])
				}
				this.miaosDa = data2.splice(0, 4)
				this.swlist = res.data.indexBanners.map((v) => {
					return {
						image: v
					}
				})
			})
		},
		// 获取活动数据
		loadmoreRe() {
			let data = {
				is_killing: 0,
				object: 'new',
				page: this.page,
				pageSize: 5
			}
			goods_list(data).then(res => {
				if (this.page == 1) {
					this.loadmoreList = res.data.data
				} else {
					this.loadmoreList = [...this.loadmoreList, ...res.data.data]
				}
			})
		},
		// 关闭弹框
		confirm() {
			this.show = false
		},
		// 跳转到分类
		goKind(kind_id) {
			uni.setStorage({ key: "kind_id", data: kind_id });
			uni.switchTab({
				url: '/pages/main/kind/kind'
			})
		},
		// 搜索框失去焦点触发
		blur() {
			uni.navigateTo({
				url: '/pages/subpackage/shop/search?data=' + this.keyword
			})
		},
		// 跳转到秒杀列表
		goSeckill() {
			uni.navigateTo({
				url: '/pages/subpackage/shop/seckill'
			})
		},
		// 跳转到秒杀详情
		goSeckillDetail(id) {
			uni.navigateTo({
				url: '/pages/subpackage/shop/seckillDetail?id=' + id
			})
		},
		// 跳转到签到
		goSign() {
			uni.navigateTo({
				url: '/pages/subpackage/shop/sign'
			})
		},
		// 跳转到商品详情页
		detail(id) {
			uni.navigateTo({
				url: '/pages/subpackage/shop/productDetail?id=' + id
			})
		},
		// 跳转到充值
		gojifc() {
			uni.navigateTo({
				url: '/pages/subpackage/my/recharge'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.index {
	.head {
		height: 350rpx;
		padding: 74rpx 30rpx;
		box-sizing: border-box;

		.head-seach {
			display: flex;
			align-items: center;
			opacity: 0.6;
			height: 60rpx;
			line-height: 60rpx;
			padding: 0 30rpx;
			border-radius: 50rpx;
			background-color: #F6F6F6;

			>input {
				width: 90%;
				margin: 0 10rpx;
				padding: 0 10rpx;
				border-right: 1px solid #999999;
			}
		}
	}

	//古传十三房
	.gc {
		height: 390rpx;
		margin: 0 30rpx;
		margin-top: -165rpx;
		// border:1rpx solid red;

		>image {
			width: 100%;
			height: 100%;
		}
	}

	//通知
	.inform {
		margin: 0 30rpx;
		margin-bottom: 30rpx;
		border-radius: 3rpx;
		box-shadow: 0px 0px 5px 0px rgba(109, 109, 109, 0.24);
	}

	// 健康值
	.jiank {
		display: flex;
		justify-content: space-between;
		height: 150rpx;
		margin: 0 20rpx;
		margin-top: 15rpx;
		color: #fff;

		>view {
			text-align: center;
			height: 100%;
			width: 50%;
			color: #a22f2f;
			padding: 30rpx;
			background: url("../../../static/index/jiank_bg.png") no-repeat;
			background-size: 100% 100%;

			>text {
				display: block;
			}

			>text:nth-child(2) {
				margin-top: 6rpx;
				font-size: 40rpx;
				font-weight: 700;
			}
		}
	}

	// 金刚区
	.jg {
		display: flex;
		flex-wrap: wrap;
		list-style: none;
		height: 416rpx;
		padding: 0rpx;
		margin: 0 30rpx;
		padding: 10rpx 0;
		background-color: #fff;
		border-radius: 10rpx;
		box-shadow: 0px 0px 5px 0px rgba(109, 109, 109, 0.24);

		>li {
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			width: 25%;
			// border:1rpx solid red;

			>image {
				width: 100rpx;
				height: 100rpx;
				border-radius: 10rpx;
			}

			>text {
				margin-top: 10rpx;
				font-size: 30rpx;
			}
		}
	}

	//秒杀
	.seckill {
		display: flex;
		margin: 15rpx 30rpx 30rpx 30rpx;
		height: 290rpx;

		.seckill-left {
			width: 340rpx;
			padding: 18rpx;
			background-color: #fff;

			>view:nth-child(1) {
				display: flex;
				align-items: center;
				justify-content: space-between;

				>image {
					width: 70rpx;
					height: 47rpx;
				}

				>text {
					font-size: 22rpx;
					color: #B07412;
				}
			}

			>ul {
				display: flex;
				justify-content: space-between;
				margin: 0 10rpx;
				list-style: none;

				>li {
					display: flex;
					flex-direction: column;

					>image {
						width: 120rpx;
						height: 120rpx;
						margin-top: 15rpx;
						border-radius: 10rpx;
					}

					>text {
						display: block;
						width: 150rpx;
						text-align: center;
						font-size: 24rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					>view {
						display: flex;
						align-content: center;
						height: 45rpx;
						margin-left: -10rpx;
						margin-right: 10rpx;

						color: #fff;

						>text:nth-child(1) {
							font-size: 24rpx;
							padding: 5rpx 10rpx;

						}

						>view:nth-child(2) {
							display: flex;
							align-items: center;
							font-size: 22rpx;
							margin-left: 10rpx;


							>text {
								display: block;
								width: 50rpx;
								font-size: 12rpx;
								transform: scale(.6);

							}
						}
					}
				}

				>li:active {
					border: 6rpx dashed #fff;
				}
			}
		}

		.seckill-right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			width: 340rpx;
			margin-left: 13rpx;

			>view {
				display: flex;
				flex-direction: column;
				height: 140rpx;
				padding: 20rpx;

				>text:nth-child(1) {
					font-size: 36rpx;
					color: #FF6A35;
					margin-bottom: 10rpx;
				}

				>text:nth-child(2) {
					width: 130rpx;
					height: 40rpx;
					text-align: center;
					font-size: 24rpx;
					color: #fff;
					border-radius: 50rpx;
					;
					background: linear-gradient(to top, #FF6F2A, #FFB449);
				}
			}

			>view:nth-child(2) {
				.active {
					background: linear-gradient(to top, #874519, #E3AF65);
				}
			}
		}
	}

	//热销榜单
	.hot {
		margin: 0 30rpx;

		.hot-logo {
			display: flex;
			align-items: center;
			font-family: Source Han Serif CN, Source Han Serif CN-Regular;

			>text:nth-child(2) {
				display: block;
				width: 36rpx;
				height: 36rpx;
				text-align: center;
				line-height: 36rpx;
				margin: 20rpx 10rpx;
				font-size: 22rpx;
				color: #fff;
				border-radius: 20rpx;
				background-color: #C72712;
			}
		}

		.hot-title {
			font-size: 50rpx;
			font-family: Source Han Serif CN, Source Han Serif CN-Regular;
		}

		.hot-titlesd {
			display: block;
			margin-top: 10rpx;
			margin-bottom: 30rpx;
			font-size: 30rpx;
			font-family: Source Han Sans CN, Source Han Sans CN-Regular;
			color: #999999;
		}

		.title-img {
			width: 100%;
			height: 420rpx;
			border-radius: 15rpx;
		}

		>ul {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			>li {
				text-align: center;
				width: 340rpx;
				height: 580rpx;
				margin-top: 20rpx;
				border-radius: 15rpx;
				overflow: hidden;
				background-color: #fff;

				>image {
					width: 100%;
					height: 340rpx;
				}

				>text:nth-child(2) {
					display: block;
					text-align: center;
					font-size: 30rpx;
					margin: 20rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				>view:nth-child(3) {
					display: flex;
					align-items: center;
					justify-content: center;
					margin: 20rpx 0;
					font-size: 36rpx;
					color: #d52e20;

					.hot-icon {
						font-size: 20rpx;
					}
				}

				>text:nth-child(4) {
					display: block;
					display: flex;
					justify-content: center;
					margin: 0 auto;
					width: 300rpx;
					height: 50rpx;
					line-height: 50rpx;
					font-family: PingFang SC, PingFang SC-Medium;
					font-weight: bold;
					color: #fff;
					background: linear-gradient(to right, #B07412, #E3BA5B);
				}
			}
		}
	}

	.pop {
		.pop-title {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 50rpx 0 60rpx 0;

			>text:nth-child(odd) {
				display: block;
				width: 48rpx;
				height: 1rpx;
				background-color: #919191;
			}

			>text:nth-child(2) {
				display: block;
				font-size: 48rpx;
				margin: 0 20rpx;
			}
		}

		.pop-cont {
			height: 240rpx;
			margin: 0 40rpx;
			overflow-y: scroll;
			// border:1rpx solid red;
		}

		.pop-btn {
			margin: 70rpx auto;
			width: 500rpx;
			height: 90rpx;
			line-height: 90rpx;
			text-align: center;
			font-size: 36rpx;
			color: #fff;
			background: linear-gradient(to right, #B07412, #E3BA5B);
		}

		.pop-btn:active {
			background: linear-gradient(to right, #E3BA5B, #E3BA5B);
		}
	}

	.u-mode-center-box {
		background-color: transparent !important;
	}
}
</style>